package com.ny.zmb.openapi.entity;

import com.baomidou.mybatisplus.annotation.TableId;
import com.ny.zmb.openapi.enums.CodeEnum;
import com.ny.zmb.openapi.enums.TransactionStatusEnum;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.lang.reflect.Type;
import java.util.Date;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class BaseObject {
    /**
     * 创建人ID
     */
    private Long created;
    /**
     * 创建时间
     */
    private Date createdDate;
    /**
     * 更新人ID
     */
    private Long updated;
    /**
     * 更新时间
     */
    private Date updatedDate;
    /**
     * 激活状态
     */
    private int active;
    /**
     * 状态
     */
    private int status;

    public void BaseObject() {
        this.active = 1;
        this.createdDate = new Date();
    }


    public void setStatus(int status) {
        this.status = status;
    }

    public void create(Integer userId) {
        this.created = Long.parseLong(userId.toString());
        this.active = 1;
        this.createdDate = new Date();
    }

    public void create(Long userId) {
        this.created = Long.parseLong(userId.toString());
        this.active = 1;
        this.createdDate = new Date();
    }

    public void update(Long userId) {
        this.updated = Long.parseLong(userId.toString());
        this.updatedDate = new Date();
    }

    public void update(Integer userId) {
        this.updated = Long.parseLong(userId.toString());
        this.updatedDate = new Date();
    }


    public void setStatus(TransactionStatusEnum transactionStatusEnum) {
        this.status = transactionStatusEnum.getStatus();
    }
    public TransactionStatusEnum getTransactionStatus(String status) {
        TransactionStatusEnum transactionStatusEnum;
        switch (status) {
            case "PROCESSING":
                transactionStatusEnum = TransactionStatusEnum.PROCESSING;
                break;
            case "WAIT_PAY":
                transactionStatusEnum = TransactionStatusEnum.WAIT_PAY;
                break;
            case "WAIT_DELIVERD":
                transactionStatusEnum = TransactionStatusEnum.WAIT_DELIVERD;
                break;
            case "WAIT_CONFIRM":
                transactionStatusEnum = TransactionStatusEnum.WAIT_CONFIRM;
                break;
            case "SUCCESS":
                transactionStatusEnum = TransactionStatusEnum.SUCCESS;
                break;
            case "CLOSED":
                transactionStatusEnum = TransactionStatusEnum.CLOSED;
                break;
            case "FAILED":
                transactionStatusEnum = TransactionStatusEnum.FAILED;
                break;
            case "REFUND_PART":
                transactionStatusEnum = TransactionStatusEnum.REFUND_PART;
                break;
            case "REFUND_ALL":
                transactionStatusEnum = TransactionStatusEnum.REFUND_ALL;
                break;
            case "REVERSAL":
                transactionStatusEnum = TransactionStatusEnum.REVERSAL;
                break;
            case "UN_KNOW":
                transactionStatusEnum = TransactionStatusEnum.UN_KNOW;
                break;
            default:
                transactionStatusEnum = TransactionStatusEnum.UN_KNOW;
                break;
        }
        return transactionStatusEnum;
    }

    public CodeEnum getCodeEnum(String status) {
        CodeEnum codeEnum;
        switch (status) {
            case "SYS000":
                codeEnum = CodeEnum.SYS000;
                break;
            case "SYS001":
                codeEnum = CodeEnum.SYS001;
                break;
            case "SYS003":
                codeEnum = CodeEnum.SYS003;
                break;
            case "SYS004":
                codeEnum = CodeEnum.SYS004;
                break;
            case "SYS005":
                codeEnum = CodeEnum.SYS005;
                break;
            default:
                codeEnum = CodeEnum.UN_KNOW;
                break;
        }
        return codeEnum;
    }

}
